package com.dcbeida.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.bean.HospitalBean;
import com.dcbeida.bean.Patient;

import java.util.ArrayList;

/**
 * 医院名称适配器
 * Created by swt on 2016/12/26.
 */
public class HospitalListAdapter extends BaseAdapter {

    private ArrayList<HospitalBean> mArrayList = new ArrayList<>();
    private Context mContext;

    public HospitalListAdapter(Context context) {
        super();
        this.mContext = context;
    }


    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.hospital_item, null, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        HospitalBean hospitalBean = mArrayList.get(position);
        holder.tv_bankcard.setText(hospitalBean.getHospitalname());
        return convertView;
    }

    private class ViewHolder {
        TextView tv_bankcard;

        ViewHolder(View view) {
            tv_bankcard = (TextView) view.findViewById(R.id.tv_bankcard);
        }

    }

    public ArrayList<HospitalBean> getmArrayList() {
        return mArrayList;
    }

    public void setmArrayList(ArrayList<HospitalBean> mArrayList) {
        this.mArrayList.clear();
        if (null != mArrayList && mArrayList.size() >= 0) {
            this.mArrayList.addAll(mArrayList);
        }
        notifyDataSetChanged();
    }
}
